<?php
/* 
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
*/

/**
 * Description of File
 *
 * @author chaporgin_a
 */
class VA_Form_FormElement_MultiFile extends VA_Form_FormElement_File {
    protected $storage = null;
    public function setStorage(VA_Form_File_Storage $storage) {
        $this->storage = $storage;
        return $this;
    }
    public function getName() {
        return parent::getName();
    }
    /**
     *
     * @return VA_Form_File_Storage
     */
    public function getStorage() {
        return $this->storage;
    }

    public function ResetValue() {
        $this->value = array();
    }

    public function setUploadedFile(VA_Form_File_UploadedFile $file) {
        $place = $this->getStorage()->Put($file);
        $this->setValue(array_merge(
                $this->getValue(),
                array($place)));
        return $place;
    }

    public function addValue(VA_Form_File_TemporaryFile $value) {
        $this->value[] = $value;
    }

    public function  __construct() {
        parent::__construct();
        if(!is_array($this->value)) $this->value = array();
    }
    protected function setDefaultDecorators() {
        $this->decorators = array();
        $this->addDecorator('ViewHelper')
                ->addDecorator('Error')
                ->addDecorator('HtmlTag', array('tag'=>'div', 'classes'=>array('element', 'multifile')))
                ->addDecorator('Label', array('position' => VA_Form_Decorator_Label::PREPEND))
                ->addDecorator('HtmlTag', array('tag'=>'div', 'jQueryMark'=>'controlWrapper', 'classes'=>array('elementWrapper')));
    }

    public function getPrintableValue() {
        $return = array();
        /* @var $value VA_Form_File_TemporaryFile */
        foreach ($this->getValue() as $value) {
            $return[] = $value->getFilename();
        }
        return join(', ',$return);
    }
    /*public function getHTMLTagAttribute($name, $onlyValue = FALSE) {
        $return = parent::getHTMLTagAttribute($name, $onlyValue);
        if($name === 'name') {
            if($onlyValue) {
                $return .= '[]';
            } else {
                $return = substr($return, 0, strlen($return)-1).'[]'.substr($return, strlen($return)-1);
            }
        }
        return $return;
    }*/
}

